/* Copyright (c) 2025 Beijing Semidrive Technology Corporation
 * SPDX-License-Identifier: Apache-2.0
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * @file    debug.h
 * @brief   DBG definitions.
 */

#ifndef DBG_H
#define DBG_H

#define ERROR_LEVEL     1
#define INFO_LEVEL      2

#if defined(CFG_NOT_USED_AUTOSAR_OS)

#include "Mcal_MemLibc.h"
extern int mini_printf(const char *fmt, ...);
#if defined(CFG_MULTI_CORE_SMP)
#include "__regs_base.h"
#include "Semag.h"

#define PRINT(fmt, args...)  do{\
                                while(sdrv_semag_trylock(SDRV_SEMAG_UART));\
                                (void)mini_printf(fmt, ##args);\
                                sdrv_semag_unlock(SDRV_SEMAG_UART);\
                            }while(0)
#else
#define PRINT(fmt, args...)  (void)mini_printf(fmt, ##args);
#endif /** #if defined(CFG_MULTI_CORE_SMP) */

#if !defined(CFG_DEBUG_LEVEL)
#define CFG_DEBUG_LEVEL 1
#warning "CFG_DEBUG_LEVEL not defined, will use default value 1. You may want to define it as 0 in production phase"
#endif /** #if !defined(CFG_DEBUG_LEVEL) */

#if CFG_DEBUG_LEVEL >= INFO_LEVEL
#define DBG    PRINT
#else
#define DBG(...)
#endif

#if CFG_DEBUG_LEVEL >= ERROR_LEVEL
#define ERROR  PRINT
#else
#define ERROR(...)
#endif

#else /** #if defined(CFG_NOT_USED_AUTOSAR_OS) */

#define PRINT(...)
#define DBG(...)
#define ERROR(...)
#endif /** #if defined(CFG_NOT_USED_AUTOSAR_OS) */

#endif /* __DBG_H__ */
